package com.ybxx.base.service.impl;

import java.util.List;

import com.ybxx.base.dao.HydropowerItemDao;
import com.ybxx.base.model.HydropowerItem;
import com.ybxx.base.service.HydropowerItemService;
import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.dao.GenericDao;
import com.ybxx.core.service.impl.BaseServiceImpl;
import com.ybxx.core.web.paging.PagingBean;

public class HydropowerItemServiceImpl extends BaseServiceImpl<HydropowerItem>
		implements HydropowerItemService {
	private HydropowerItemDao hydropowerItemDao;
	public HydropowerItemServiceImpl(HydropowerItemDao dao) {
		super(dao);
		this.hydropowerItemDao=dao;
		// TODO Auto-generated constructor stub
	}
	public List<HydropowerItem> queryHydropowerItem(String cid) {
		String hql="from HydropowerItem hi left join fetch hi.type ht where hi.hydropower.community.cid='"+cid+"' order by ht.tid,hi.rmin";
		return hydropowerItemDao.findByHql(hql, null);
	}
	/*检查水电指标配置*/
	public int checkConfig(String unitid,String tid){
		String hql="from HydropowerItem hi left join fetch hi.type ht " +
	            "left join fetch hi.hydropower h left join fetch h.community c " +
	            ",Ban b " +
	            ",Unit u " +
	            ",Room r "+
				"where c.cid=b.community.cid and b.bid=u.ban.bid and r.unit.uid=u.uid and ht.tid='"+tid+"' ";
		if(unitid.indexOf("R")==0){
			hql+=" and r.rid='"+unitid.substring(1)+"'";
		}
		if(unitid.indexOf("U")==0){
			hql+=" and u.uid='"+unitid.substring(1)+"'";
		}
		if(unitid.indexOf("B")==0){
			hql+=" and b.bid='"+unitid.substring(1)+"'";
		}
		if(unitid.indexOf("C")==0){
			hql+=" and c.cid='"+unitid.substring(1)+"'";
		}
		return hydropowerItemDao.findCountByHql(hql, null);
	}

}
